const { MilvusClient,DataType } = require('@zilliz/milvus2-sdk-node');
//创建客户端
const milvusClient = new MilvusClient({
    address: 'localhost:19530',
    timeout: 100000
})
const db_name = 'blog';
const collection_name = 'articles';
const field_name ='title_vector';
(async function () {
    try {
        await milvusClient.useDatabase(db_name);
        console.log('已经成功切换到了' + db_name);
        const articles = [
            {
                id:1,
                title:'中国',
                title_vector:[0.1,0.2,0.3]
            },
            {
                id:2,
                title:'伟大',
                title_vector:[0.4,0.5,0.6]
            }
        ]
        const insertResult = await milvusClient.insert({
            collection_name,//向哪个集合中插入Entity
            fields_data:articles
        })
        console.log(insertResult);
        const updateArticles = [
            {
                id:1,
                title:'中国1',
                title_vector:[0.11,0.21,0.31]
            },
            {
                id:2,
                title:'伟大1',
                title_vector:[0.41,0.51,0.61]
            },
            {
                id:3,
                title:'祖国',
                title_vector:[0.7,0.8,0.9]
            }
        ]
        //upsert=update+insert
        const upsertResult = await milvusClient.upsert({
            collection_name,
            fields_data:updateArticles
        });
        console.log(upsertResult);
      /*   await milvusClient.delete({
            collection_name,
            filter:'id in [1,2]'
        }) */
    } catch (error) {
        await milvusClient.closeConnection();
        process.exit(1)
    }

})()